//
//  DMShareCodeView.m
//  DistributionMall
//
//  Created by JHnoplan on 2018/10/16.
//  Copyright © 2018年 JHnoplan. All rights reserved.
//

#import "DMShareCodeView.h"

#define mainView_H 250
@interface DMShareCodeView ()


@end

@implementation DMShareCodeView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self= [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        
        [self makeUI];
    }
    return self;
}

-(void)makeUI {
    self.hidden = YES;
    
    _bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    _bgView.backgroundColor = [UIColor blackColor];
    _bgView.alpha = 0.4;
    UITapGestureRecognizer * disTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideClick)];
    [_bgView addGestureRecognizer:disTap];
    [self addSubview:_bgView];
    
    _mainView = [[UIView alloc]initWithFrame:CGRectMake(0, ScreenHeight, ScreenWidth, mainView_H)];
    _mainView.backgroundColor = DMWhiteColor;
    //设置阴影
    _mainView.layer.shadowColor = [UIColor blackColor].CGColor;//阴影颜色
    _mainView.layer.shadowOpacity = 0.9;//阴影透明度，默认0
    _mainView.layer.shadowRadius = 8.0;//阴影半径，默认3
    _mainView.layer.shadowOffset = CGSizeMake(0, 3);//阴影偏移，默认(0, -3)
    [self addSubview:_mainView];
    
    NSArray *imageArr = @[@"fenxiang_qq",@"fenxiang_qqkongjian",@"fenxiang_wechat",@"denxiang_pegyouquan",@"fenxiang_weibo"];
    NSArray *titleArr = @[@"QQ",@"QQ空间",@"微信",@"朋友圈",@"微博"];
    
    CGFloat width = ScreenWidth/4;
    CGFloat height = 96;
    for (int i = 0; i < imageArr.count; i++) {
        int hang = i/4;
        int lie = i%4;
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(lie*width, hang*height, width, height)];
        view.tag = 100+i;
        [_mainView addSubview:view];
        
        UIImageView *iv = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
        iv.center = CGPointMake(width/2, 45);
        iv.image = [UIImage imageNamed:imageArr[i]];
        [view addSubview:iv];
        
        UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(0, 76, width, 20)];
        title.text = titleArr[i];
        title.textColor = DMFontColor;
        title.font = DMFontSize(14);
        title.textAlignment = NSTextAlignmentCenter;
        [view addSubview:title];
        
        view.userInteractionEnabled = YES;
        [view addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(buttonClick:)]];
    }
    
    UIButton *cancel = [[UIButton alloc]initWithFrame:CGRectMake(0, mainView_H-57, ScreenWidth, 57)];
    [cancel setTitle:@"取消" forState:UIControlStateNormal];
    [cancel setTitleColor:DMFontColor forState:UIControlStateNormal];
    cancel.titleLabel.font = DMFontSize(18);
    [cancel addTarget:self action:@selector(hideClick) forControlEvents:UIControlEventTouchUpInside];
    [_mainView addSubview:cancel];
}

-(void)buttonClick:(UITapGestureRecognizer *)tap {
    NSLog(@"%ld",tap.view.tag-100);
    
}

-(void)showView {
    self.hidden = NO;
    [UIView animateWithDuration:0.3 animations:^{
        _mainView.frame = CGRectMake(0, ScreenHeight-mainView_H, ScreenWidth, mainView_H);
    }];
}

-(void)hideClick {
    [UIView animateWithDuration:0.3 animations:^{
        _mainView.frame = CGRectMake(0, ScreenHeight, ScreenWidth, mainView_H);
    } completion:^(BOOL finished) {
        self.hidden = YES;
    }];
}

@end
